import Dile_Methods from "@/utils/methods";
import { object_Inf } from "@/utils/typings/index.type";
import Utils_Statistic from "../utils-statistic";

/*
 * @Descripttion:保养计划工具类
 * @LastEditors: xzh
 * @LastEditTime: 2024-05-11 09:13:10
 */
export default class Utils_UpKeepPlan extends Utils_Statistic {
  /**
   * @Author: xzh
   * @Descripttion: 保养任务状态
   * @Param:
   */
  static upkeepTaskStatusArr = [
    {
      icon: "toBeExecuted",
      background: "#506ABC",
    },
    {
      icon: "inUpkeep",
      background: "#EE6666",
    },
    {
      icon: "beOverdue",
      background: "#FAC858",
    },
    {
      icon: "unexecuted",
      background: "#70BBD8",
    },
    {
      icon: "completed",
      background: "#91CC75",
    },
  ];
  /**
   * @Author: xzh
   * @Descripttion: 获取保养状态图表
   * @Param:
   */
  static getUpkeepStatusChart = (
    upkeepStatus: object_Inf,
    param: object_Inf = {}
  ) => {
    let { dataArr = [], title } = upkeepStatus,
      { cover } = param;
    return {
      option: {
        tooltip: {
          trigger: "item",
        },
        color: ["#506ABC", "#EE6666", "#FAC858", "#70BBD8", "#91CC75"],
        title: {
          text: title,
          left: "center",
          top: "center",
        },
        legend: {
          bottom: 0,
          left: "center",
          data: dataArr?.map((x: object_Inf) => x.name),
        },
        grid: {
          top: "3%",
          left: "1%",
          right: "1%",
          containLabel: true,
        },
        series: [
          {
            type: "pie",
            radius: ["40%", "70%"],
            label: {
              show: true,
              formatter({ data }: object_Inf) {
                let { value, suffix } = data;
                return `${value}${suffix}`;
              },
            },
            data: dataArr.map(({ name, data, suffix }: object_Inf) => ({
              name,
              suffix,
              value: data.find(() => true),
            })),
          },
        ],
        //图表覆盖配置
        ...(cover || {}),
      },
      id: Dile_Methods.newGuid(),
    };
  };
  /**
   * @Author: xzh
   * @Descripttion: 获取保养任务图表
   * @Param:
   */
  static getUpkeepTaskChart = (ukeepTask: object_Inf) => {
    let { dataArr = [], title } = ukeepTask;
    return {
      option: {
        title: {
          text: title,
          subtext: "任务完成率",
          left: "center",
          top: "center",
        },
        tooltip: {
          trigger: "item",
        },
        color: ["#D7D7D7", "#91cc75"],
        grid: {
          top: "3%",
          left: "1%",
          right: "1%",
          containLabel: true,
        },
        series: [
          {
            type: "pie",
            radius: ["50%", "70%"],
            label: {
              show: false,
            },
            data: dataArr?.map(({ name, data, suffix }: object_Inf) => ({
              name,
              suffix,
              value: data.find(() => true),
            })),
          },
        ],
      },
      id: Dile_Methods.newGuid(),
    };
  };
}
